//
//  TDPaths.m
//  iosf
//
//  Created by Yuan Ye on 12-4-4.
//  Copyright (c) 2012年 Neusoft Corporation. All rights reserved.
//

#import "TDPaths.h"

NSString* TDPathForBundleResource(NSBundle* bundle, NSString* relativePath) {
  NSString* resourcePath = [(nil == bundle ? [NSBundle mainBundle] : bundle) resourcePath];
  return [resourcePath stringByAppendingPathComponent:relativePath];
}

NSString* TDPathForDocumentsResource(NSString* relativePath) {
  static NSString* documentsPath = nil;
  if (nil == documentsPath) {
    NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                        NSUserDomainMask,
                                                        YES);
    documentsPath = [[dirs objectAtIndex:0] retain];
  }
  return [documentsPath stringByAppendingPathComponent:relativePath];
}

NSString* TDPathForCachesResource(NSString* relativePath) {
  static NSString* cachesPath = nil;
  if (nil == cachesPath) {
    NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
                                                        NSUserDomainMask,
                                                        YES);
    cachesPath = [[dirs objectAtIndex:0] retain];
  }
  return [cachesPath stringByAppendingPathComponent:relativePath];
}
